package com.gkj.listener;

import com.gkj.blog.business.consts.SessionConst;
import com.gkj.blog.util.FileUtil;
import com.gkj.blog.util.QiniuApi;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.List;

public class UploadImageSessionListener implements HttpSessionListener{

    @Override
    public void sessionCreated(HttpSessionEvent se) {

    }

    /**
     * 删除用户未提交且上传了的图片
     * @param se
     */
    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        List<String> editImages= (List<String>) se.getSession().getAttribute(SessionConst.EDIT_IMAGES);
        QiniuApi qiniuApi = QiniuApi.getInstance();
        editImages.forEach((e)->{
            qiniuApi.delete(e);
        });
    }
}
